package com.taoyibao.hongcanting.http;

/**
 * httpCode !=200时
 */
public class ApiException extends RuntimeException {

    public int errorCode;
    public String errorMsg;
    private static final int USER_EXPIRE = 40000;

    public ApiException(int errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        getApiExceptionMessage(errorCode, errorMsg);
    }

    /**
     * 处理特殊异常  例如token失效等
     *
     * @param code
     * @return
     */
    private String getApiExceptionMessage(int code, String defaultMsg) {
        errorCode = code;
        String message = "";
        switch (code) {
            case USER_EXPIRE:
                message = "登录已过期，请重新登录";
            default:
                message = defaultMsg;

        }
        return message;
    }
}

